package ssm.com.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/*全局处理异常
在这个类上使用@ControllerAdvice注解，标记这个类是用来处理全局异常的一个类
*/
@ControllerAdvice
public class ExceptionHandlerController {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String,Object> doException(Exception e){
        HashMap<String, Object> map = new HashMap<>();
        map.put("state",500);
        //map.put("msg","服务器正忙，请稍后重试");
        map.put("msg",e.getMessage());
        //System.out.println(map.get("msg"));
        return map;
    }
}
